package com.alipay;

import java.text.DecimalFormat;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.constants.AlipayServiceEnvConstants;
import com.alipay.factory.AlipayAPIClientFactory;
import com.lianlianpay.bean.QuickPayMentBean;
import com.seek.util.CommonUtil;

public class AliPay {
	private static Logger logger = LoggerFactory.getLogger(AliPay.class);
	public static QuickPayMentBean aliPay (Map<String,Object> map){
		QuickPayMentBean quick = new QuickPayMentBean();
		String payMoney=new DecimalFormat("##0.00").format((double)CommonUtil.getIntValue(map.get("payMoney"))/100);
		//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
		AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
		//SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
		AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
		model.setBody("金额："+payMoney);
		model.setSubject("花金宝产品");
		model.setOutTradeNo(map.get("repayId")+"");
		model.setTimeoutExpress("30m");
		model.setTotalAmount(payMoney);
		model.setProductCode("QUICK_MSECURITY_PAY");
		request.setBizModel(model);
		request.setNotifyUrl(AlipayServiceEnvConstants.NOTIFY_URL);
		try {
		        //这里和普通的接口调用不同，使用的是sdkExecute
			AlipayTradeAppPayResponse response = AlipayAPIClientFactory.getAlipayClient().sdkExecute(request);
			logger.info("==============================response.getBody(){}",response.getBody());
		        quick.setAlipay(response.getBody());
		    } catch (AlipayApiException e) {
		        e.printStackTrace();
		}
		 return quick;
	}

}
